<?php
    session_start();
    
    if($_SERVER['REQUEST_METHOD'] == "POST") {
        include("conexion.php");
        $conn = new mysqli($dbhost, $dbuser, $dbpass, $db);
        
        $user = strtoupper(str_replace("'", "", $_POST["txtNombUsua"]));
        $pass = strtoupper(str_replace("'", "", $_POST["txtNombPass"]));
        
        $tabla = $conn->query("SELECT * FROM usuarios WHERE NombUsua = '{$user}' AND NombPass = '{$pass}'");

        $strSalida = "";
        
        if ($tabla->num_rows > 0)
        {
        	$fila = $tabla->fetch_array();
            $_SESSION['is_logged_in'] = 1;
            $_SESSION['NombUsua'] = $fila['NombUsua'];
            $_SESSION['intNumeCarg'] = $fila['NumeCarg'];
            
            $tabla = $conn->query("SELECT NumeEqui FROM equipos WHERE NumeUsua = ".$fila['NumeUsua']);
            if (($tabla->num_rows > 0) && ($_SESSION['intNumeCarg'] == $CARGO_EQUI)) {
            	$fila = $tabla->fetch_array();
            	$_SESSION['intNumeEqui'] =  $fila['NumeEqui'];
            }
            $strSalida = "login_correcto";
        }
        
        $tabla->free();
        $conn->close();
        
        echo $strSalida;
    }
?>